#include "Menu.h"
#include <iostream>
//additional includes
#include<string>
#include<fstream>
#include<climits>

using namespace std;

Menu::Menu()
{
}

void Menu::display_main_menu() const 
{
  cout << "\n\nHere is the MAIN MENU \n";
  /*******************************************/
  /*Created or Modified by EC*/
  /*Displays the main menu*/
  /*******************************************/
  //cout << "Appetizers: \n";
  //cout << " Kerupuk\n Pastel\n Risoles\n Rujak\n Tahu\n Spinach Onion Dip\n Nachos\n Bruschetta\n Hummis Dip\n Crepes\n Onion Rings\n";
  cout << "1 - Display info." << endl;							
  cout << "2 - Read and store data from file."	<< endl;		
  cout << "3 - Show queries."	<< endl;								
  cout << "4 - Find query."	<< endl;
  cout << "5 - Update queries." << endl;								
  cout << "6 - Exit."	<< endl;								
  cout << "Please input the number [1-6]: " << endl;
}
void Menu::display_info() const
{
  cout << "Here is the Info requested \n";
  /*********************************************************************/
  /*Created or Modified by EC*/
  /*Display assignment info & your name plus "Project Part I"*/
  /*********************************************************************/
  cout << "Project Part 1" << endl;
  cout << "Restaurant Order Management System" << endl;
  cout << "Assignment A.1: William Eka Putra" << endl;
  cout << "	When exit is selected, output a message and confirm that \n	the user did not accidently select exit. Create \n 	an Instructions type to be used in the Recipe type. \n 	Complete the read() function in Menu.cpp by reading and \n	storing the recipe and ingredients data file." << endl;
  cout << "Assignment A.2: Ross Dixon" << endl;
  cout << "	The program should output its own identification information \n 	before displaying the initial main menu. Add \n 	the Date type from Chapter 9 to the project for use \n 	in the Order type. Add a Time type. Complete the read() \n	function in Menu.cpp by reading and storing \n 	the order and order item data." << endl;
  cout << "Assignment A.3: Erick Chaves" << endl;
  cout << "	Complete the display_main_menu() and display_info() for the \n 	Menu.cpp type. Create a Description type to be \n 	used in the Menu_Item type. Complete the read() function \n	in Menu.cpp by reading and storing the category and menu \n	item data." << endl;

}

void Menu::read()
{
  cout << "Read file name then read store data \n";

  /*******************************************/
  /*Created or Modified by EC*/
  /*Added read and store for catmenu.dat*/
  /*******************************************/
  //variables
  int num_cats, num_items, menu_item_ID, cat_ID, recipe_ID;
  double item_price;
  //ifstream catmenu;
  string cat_file_name, cat_name, item_name, description, words;
  Category cat;
  Description descr;
	
  //do
  //{
  //cout << "Input category and menu file name: "; //input "catmenu.dat"
  //cin >> cat_file_name;
  //catmenu.open(cat_file_name.c_str()); //open catmenu.dat
  ifstream catmenu("../sample data/catmenu.dat");
	
  if (catmenu.is_open())
    {
      catmenu >> num_cats; //read number of categories
      //cout << "number of categories: " << num_cats << endl; //only for testing
      for (int i = 0; i < num_cats; i++) //iterates 4 times
	{
	  catmenu >> cat_ID >> cat_name;
	  //cout << "cat_ID: " << cat_ID << "\n cat_name: " << cat_name << endl; //only for testing
	  //storing using category setter
	  cat.setCategoryID(cat_ID);
	  cat.setCategoryName(cat_name);
	  Menu::categories.push_back(cat);
	  //cout << cat.getCategoryID() << endl << cat.getCategoryName() << endl; //only for testing
	}
      catmenu >> num_items; //read amount of menu items.
      //cout << "Number of menu items: " << num_items << endl; //only for testing
		
      for(int i = 0; i < num_items; i++) //iterates 11 times
	{
	  catmenu >> menu_item_ID >> cat_ID >> recipe_ID >> item_name >> item_price >> description; //read the information
	  description += " ";
	  catmenu >> words; //used to search until # is found
	  while (words!= "#")//search until # is found
	    {
					
	      description += words + " ";// append words in the description into one sentance
	      catmenu >> words;
	    }
	  //cout << "\n Item ID: " << menu_item_ID << "\n Category ID: " << cat_ID << "\n Recipe ID: " << recipe_ID << "\n Item name: " << item_name << "\n Item price: " << item_price << "\n Description: " << description << endl; //for testing only
	  //storing using Description setter
	  descr.setMenuItemID(menu_item_ID);
	  descr.setCategoryID(cat_ID);
	  descr.setRecipeId(recipe_ID);
	  descr.setMenuItemName(item_name);
	  descr.setMenuItemPrice(item_price);
	  descr.setDescription(description);
	  Menu_Item item = Menu_Item(menu_item_ID, cat_ID, recipe_ID, item_name, item_price, descr);
	  Menu::menu_items.push_back(item);
	}
    }
  else
    {
      cout << "The file doesn't exist. Suggestion: catmenu.dat" << endl << endl; //error handling for wrong file.
    }
  //}while(!catmenu.is_open());
  cout << "Categories and Menu items have been read and stored." << endl;

  /* Order read() by RCD
     Read and store order and order item data
  */
  int order_id, server_id, table_id, menu_item_id, prod_qty, year, month, day, hour, minute, num_orders, num_ord_items;
  Date order_date;
  Time order_time;
  //string order_file_name;
  char seat_id;
  Order ord;
  Order_Item item;
  //ifstream order_in;

  //do {
  //cout << "Enter order and order item file name: ";
  //cin >> order_file_name;
  //order_in.open(order_file_name.c_str());
  ifstream order_in("../sample data/orders.dat");
  if(order_in.is_open()) {
    order_in >> num_orders;
    for(int i = 0; i < num_orders; i++) {
      order_in >> order_id >> server_id >> table_id >> year >> month >> day >> hour >> minute;
      order_date = Date(year, (Date::Month)month, day);
      order_time = Time(hour, minute);
      ord = Order(order_id, server_id, table_id, order_date, order_time);
      Menu::orders.push_back(ord);
    }
    order_in >> num_ord_items;
    for(int i = 0; i < num_ord_items; i++) {
      order_in >> seat_id >> order_id >> menu_item_id >> prod_qty;
      item = Order_Item(seat_id, order_id, menu_item_id, prod_qty);
      Menu::order_items.push_back(item);
    }
  }
  else {
    cout << "\nFile doesn't exist. Try orders.dat\n";
  }
  //} while(!order_in.is_open());
  cout << "Orders and order items have been read and stored.\n";
	

  /*********************************************************************/
  /*Created or Modified by WEP*/
  /*Reading and Storing data in recipes.dat*/
  /*********************************************************************/
  // Local variables
  string fileName, temp, unit, ing_name, chef_name, inst, sharp;
  //ifstream recipes;
  int ing_amount, ing_id, rec_id, inst_amount;
  float amount;
  Ingredient ing;
  Instructions instruct;

  // Read process
  //do
  //{
  //cout << "Input recipes and ingredients file name: "; // input the file's name
  //cin >> fileName;
  //recipes.open(fileName.c_str()); // open the file; it should be recipes.dat
  ifstream recipes ("../sample data/recipes.dat");
		
  if (recipes.is_open())
    {
      //cout << "opened" << endl; //only for testing
      recipes >> ing_amount; // read amount of ingredients
      //cout << "ingredients amount : " << ing_amount <<endl; //only for testing

      for(int i = 0; i < ing_amount; i++) // iterating 101 times
	{
	  recipes >> ing_id >> rec_id >> amount >> unit >> ing_name; // read the others information
	  //cout << "ing_id: " << ing_id << ", rec_id: " << rec_id << ", amount: " << amount << ", unit: " << unit << ", ing_name: " << ing_name << endl; //only for testing
	  // storing using setter
	  ing.setIngredientId(ing_id);
	  ing.setRecipeId(rec_id);
	  ing.setAmount(amount);
	  ing.setUnits(unit);
	  ing.setName(ing_name);
	  Menu::ingredients.push_back(ing);
	  //cout << ing.getIngredientId() << ing.getRecipeId() << ing.getAmount() << ing.getUnit() << ing.getName() << endl; //only for testing
	}

      recipes >> inst_amount; // read amount of instructions
      //cout << "instruction amount : " << inst_amount <<endl; //only for testing

      for(int i = 0; i < inst_amount; i++) // iterating 11 times
	{
	  recipes >> rec_id >> chef_name; // read the others information
	  recipes >> sharp; // special case for instructions, we must search until # symbol
	  while (sharp != "#") // do the reading until # is found
	    {
	      if ((sharp == "2.") || (sharp == "3.") || (sharp == "4.") || (sharp == "5.") || (sharp == "6.") || (sharp == "7.")) // just to make it neat
		{
		  inst += "\n" + sharp; // new line between new instructions
		  recipes >> sharp;
		}
	      else
		{
		  inst += sharp + " "; // append words into one sentence
		  recipes >> sharp;
		}
	    }

	  //storing using setter
	  instruct.setRecipeId(rec_id);
	  instruct.setInstructions(inst);
	  Recipe rec = Recipe(rec_id, chef_name, instruct);
	  Menu::recipes.push_back(rec);
	  //cout << rec_id << endl <<chef_name << endl; //only for testing
	  //cout << inst << endl; //only for testing
	  inst = "";
	}

    }
  else
    {
      cout << "The file doesn't exist. Suggestion: recipes.dat" << endl << endl; // error handling for wrong file name
    }
  //}
  //while (!recipes.is_open());
  cout << "Reading and Storing recipes.dat was successful" << endl;
	
}
void Menu::show() const 
{
  cout << "Show queries \n";

  //Category cat;
  char entry;	//record letter choice
  cout << "Enter A to print menu item recipe.\n";	//use letters to make choice
  cout << "Enter B to print all menu items sorted by Chef.\n";
  cout << "Enter C to print all menu items in a given category sorted by price.\n";
  cout << "Enter D to list all order IDs and the tab price sorted by date.\n";
  cout << "Enter E to list all menu item in a given order by price.\n";
  cout << "> ";
  cin >> entry;
  while(!cin) {	//if entry was invalid
    cin.clear();	//reset cin state
    cin.ignore(INT_MAX, '\n');	//clear cin buffer
    cout << "Invalid entry, please try again.\n";
    cout << "> ";
    cin >> entry;
  }
  if(entry == 'A' || entry == 'a') 
    {
      /*
	Modified by RCD
	B1a
      */
      cin.ignore(INT_MAX, '\n');
      bool found = false;
      int menu_item_id;
      int recipe_id;
      cout << "Enter ID of menu item.\n";
      cout << "> ";
      cin >> menu_item_id;
      while(!cin) {
	cin.clear();
	cin.ignore(INT_MAX, '\n');
	cout << "Invalid entry, please try again.\n";
	cout << "> ";
	cin >> menu_item_id;
      }
      for(unsigned int i = 0; i < menu_items.size(); i++) {
	if(menu_item_id == menu_items[i].item_id()) {
	  found = true;
	  recipe_id = menu_items[i].recipe();
	  cout << "\nName: " << menu_items[i].item_name() << '\n';
	  cout << "Description: " << menu_items[i].descrip().getDescription() << '\n';
	}
      }
      if(found) {
	cout << "Ingredients: \n";
	for(unsigned int i = 0; i < ingredients.size(); i++) {
	  if(recipe_id == ingredients[i].getRecipeId()) {
	    cout << ingredients[i].getAmount() << '\t' << ingredients[i].getUnits() << '\t' << ingredients[i].getName() << '\n';
	  }
	}
	cout << "\nInstructions: \n";
	for(unsigned int i = 0; i <recipes.size(); i++) {
	  if(recipe_id == recipes[i].recipe()) {
	    cout << recipes[i].instruct().getInstructions() << '\n';
	  }
	}
      }
      else
	cout << "Menu item not found. Ending query.\n";
    }
  /*End modification by RCD
    B1a
  */
  else if(entry == 'B' || entry == 'b') 
    {
      /************************************************************/
      /*Created or Modified by EC*/
      /*B.1b: Print all menu items sorted by Chef (Print item name, ID and price)*/
      /************************************************************/

      cout << "Show queries \n\n";
      cout << "Menu items sorted by Chef: \n\n";
      string chef;
      vector<int> indices; //vector of recipes that contain chef
      vector<int> recipe_ids; //vector of recipe_ids corresponding to each chef
	
      for(unsigned int i = 0; i < recipes.size(); i++) {  //search through vector Menu::recipes for any chef
	chef = recipes[i].chef();
	indices.push_back(i);  //record index of recipes that is associated with the chef
      }

      for(unsigned int i = 0; i < indices.size(); i++) {  //loop records recipe_ids of recipe associated with the chef
	recipe_ids.push_back(recipes[indices[i]].recipe());
      }
	
      for(unsigned int i = 0; i < recipe_ids.size(); i++){  //go through recipe_ids of recipes associated with chef
	int current_recipe_id = recipe_ids[i];  //record recipe_id of current vector subscript
	for(unsigned int j = 0; j < recipe_ids.size(); j++) {  //go through Menu::menu_items and print out any menu_item that matches recipe_id of the corresponding chef
	  if(current_recipe_id == menu_items[j].recipe()) {
	    cout << recipes[j].chef() << ":\t" << menu_items[j].item_name() << "\t" << menu_items[j].item_id() << "\t" << menu_items[j].item_price() << '\n';
	  }
	}
      }
    }

  /*********************************************************************/
  /*Created or Modified by WEP*/
  /*Show query, B1C*/
  /*********************************************************************/
  else if(entry == 'C' || entry == 'c') 
    {
      cin.ignore(INT_MAX, '\n');	//clear any leftover data in cin buffer
      int in_cat;	//table which user is requesting sales for
      bool found = false;

      cout << "Category ID\tCategory Name" << endl;
      for (unsigned int i = 0; i < categories.size(); i++)
	{
	  cout << categories[i].display() << endl;
	}
      cout << "Enter the category id which you would like to print.\n";
      cout << "> ";
      cin >> in_cat; //input category id
      while(!cin) {	//if input is invalid
	cin.clear();	//reset cin state
	cin.ignore(INT_MAX, '\n'); //clear cin buffer
	cout << "Invalid entry, please try again.\n";
	cout << "> ";
	cin >> in_cat;
      }

      //searching the category id
      for(unsigned int i = 0; i < categories.size(); i++) 
	{	
	  if(in_cat == categories[i].getCategoryID()) 
	    {
	      found = true;	
	    }
	}
      //cout << categories.size() << endl;
      //cout << menu_items.size() << endl;
      //cout << category << endl;
      if (found == true)
	{
	  //Go through the menu items
	  vector<Menu_Item> vec_Sort;
	  for (unsigned int i = 0; i < menu_items.size(); i++) 
	    {
	      if (menu_items.at(i).category() == in_cat) 
		{
		  vec_Sort.push_back(menu_items.at(i));
		}
	      //cout << menu_items[i].item_name() << endl;
	      //cout << Sorted.size() << endl;
	    }

	  // Sorting process, basically a swap sort
	  for (int rep = 0; rep < 2; rep ++) //twice, just to make sure it is sorted
	    {
	      for (unsigned int i = 1; i < vec_Sort.size(); i++) 
		{
		  Menu_Item iter = vec_Sort.at(i);
		  int before = i - 1;//comparor
		  while (before >= 0 && iter.item_price() < vec_Sort.at(before).item_price()) 
		    {
		      //swap process
		      vec_Sort.insert(vec_Sort.begin() + i + 1, vec_Sort.at(before));//insert after the next
		      vec_Sort.erase(vec_Sort.begin() + before);//delete the redundant data before
		      before--;
		    }
		}
	    }

	  if (vec_Sort.empty()) //if the category doesn't contain any menu
	    {
	      cout << "No menu items with such category." << endl;
	    }
	  else
	    {
	      //after the list is sorted, print. by price
	      for (unsigned int i = 0; i < vec_Sort.size(); i++)
		{
		  cout << "Item's name\t\t: " << vec_Sort[i].item_name() << endl;
		  cout << "Item's price\t\t: " << vec_Sort[i].item_price() << endl;
		  cout << "Item's description\t: " << vec_Sort[i].descrip().getDescription() << endl << endl;
		}
	    }
	}
      else	//no order with a matching cat_id was found
	cout << "ERROR: Category doesn't exist. Ending query.\n";	//inform user, return to main menu
    }
  /*********************************************************************/
  /*End part by WEP*/
  /*********************************************************************/


  /***
      by RCD
      C.1a
  ***/
  else if(entry == 'D' || entry == 'd') {
    vector<double> prices;	//vector of total prices for orders
    vector<Order> sorted_orders = orders;	//same as orders vector, but will be sorted
    vector<Order> curr_orders;	//used during sorting to sort a chunk of sorted_orders at a time
    bool swapped = true;	//used during buuble sort
    int curr_year;	//used during sorting, current year in which months are being sorted
    Date::Month curr_month;	//used during sorting, current month in which days are being sorted
    int curr_day;	//used during sorting, current day in which hours are being sorted
    int curr_hour;	//used during sorting, curren hour in which minutes are being sorted

    /*****
	  Date and Time Sorting
    *****/
    
    //bubble sort
    for(int i = 0; swapped; ) {
      swapped = false;	//swapped stays false until something is swapped, if nothing is swapped sorting must be done
      i++;
      for(unsigned int j = 0; j < sorted_orders.size()-i; j++) {
	if(sorted_orders[j].o_date().year() > sorted_orders[j+1].o_date().year()) {
	  Order tmp;
	  tmp = sorted_orders[j];
	  sorted_orders[j] = sorted_orders[j+1];
	  sorted_orders[j+1] = tmp;
	  swapped = true;
	}
      }
    }
    //end bubble sort

 
    /*****
	  Sorting Logic:
	  sort the months of each year seperatly, so that the years stay in order
	  do this by using a temporary vector, curr_orders, and filling it with all elements from sorted_orders with the year in which were currently sorting
	  sort the elements of curr_orders using bubble sort algorithm
	  now that the elements of curr_order are sorted, put them back into sorted_orders, replacing the old unsorted elements from which curr_orders was made
	  increment k so that the next section of sorting starts just beyond the just sorted chunk of sorted_orders
    *****/
    //sort month within year
    swapped = true;
    for(unsigned int k = 0; k < sorted_orders.size(); ) {	//sort entire vector
      curr_orders.clear();	//make sure working sort vector clear
      curr_year = sorted_orders[k].o_date().year();	//get the year in which months will be sorted
      for(unsigned int l = k; sorted_orders[l].o_date().year() == curr_year && l < sorted_orders.size(); l++) {	//make curr_orders contain every value of sorted_orders in which year == curr_year
	curr_orders.push_back(sorted_orders[l]);
      }
      //bubble sort
      for(int i = 0; swapped; ) {
	swapped = false;	//swapped stays false until something is swapped, if nothing is swapped sorting must be done
	i++;
	for(unsigned int j = 0; j < curr_orders.size()-i; j++) {
	  if(curr_orders[j].o_date().month() > curr_orders[j+1].o_date().month()) {
	    Order tmp = curr_orders[j];
	    curr_orders[j] = curr_orders[j+1];
	    curr_orders[j+1] = tmp;
	    swapped = true;
	  }
	}
      }
      //end bubble sort
      swapped = true;
      for(unsigned int l = 0; l < curr_orders.size(); l++) {	//replace the elements of sorted_orders with the now sorted elements of curr_orders
	sorted_orders[k+l] = curr_orders[l];
      }
      for(unsigned int i = 0; i < curr_orders.size(); i++) {	//increment the starting index for next sorting operation
	k++;
      }
    }
    /*****
	  the following sort blocks follow the same logic as the above sort block, just comparing and sorting different values
    *****/
    
    
    //sort day within month
    swapped = true;
    for(unsigned int k = 0; k < sorted_orders.size(); ) {
      curr_orders.clear();
      curr_month = sorted_orders[k].o_date().month();
      for(unsigned int l = k; sorted_orders[l].o_date().month() == curr_month && l < sorted_orders.size(); l++) {
	curr_orders.push_back(sorted_orders[l]);
      }
      //bubble sort
      for(int i = 0; swapped; ) {
	swapped = false;
	i++;
	for(unsigned int j = 0; j < curr_orders.size()-i; j++) {
	  if(curr_orders[j].o_date().day() > curr_orders[j+1].o_date().day()) {
	    Order tmp = curr_orders[j];
	    curr_orders[j] = curr_orders[j+1];
	    curr_orders[j+1] = tmp;
	    swapped = true;
	  }
	}
      }
      //end bubble sort
      swapped = true;
      for(unsigned int l = 0; l < curr_orders.size(); l++) {
	sorted_orders[k+l] = curr_orders[l];
      }
      for(unsigned int i = 0; i < curr_orders.size(); i++) {
	k++;
      }
    }
    
    //sort hour within day
    swapped = true;
    for(unsigned int k = 0; k < sorted_orders.size(); ) {
      curr_orders.clear();
      curr_day = sorted_orders[k].o_date().day();
      for(unsigned int l = k; sorted_orders[l].o_date().day() == curr_day && l < sorted_orders.size(); l++) {
	curr_orders.push_back(sorted_orders[l]);
      }
      //bubble sort
      for(int i = 0; swapped; ) {
	swapped = false;
	i++;
	for(unsigned int j = 0; j < curr_orders.size()-i; j++) {
	  if(curr_orders[j].o_time().hour() > curr_orders[j+1].o_time().hour()) {
	    Order tmp = curr_orders[j];
	    curr_orders[j] = curr_orders[j+1];
	    curr_orders[j+1] = tmp;
	    swapped = true;
	  }
	}
      }
      //end bubble sort
      swapped = true;
      for(unsigned int l = 0; l < curr_orders.size(); l++) {
	sorted_orders[k+l] = curr_orders[l];
      }
      for(unsigned int i = 0; i < curr_orders.size(); i++) {
	k++;
      }
    }

    //sort minute within hour
    swapped = true;
    for(unsigned int k = 0; k < sorted_orders.size(); ) {
      curr_orders.clear();
      curr_hour = sorted_orders[k].o_time().hour();
      for(unsigned int l = k; sorted_orders[l].o_time().hour() == curr_hour && l < sorted_orders.size(); l++) {
	curr_orders.push_back(sorted_orders[l]);
      }
      //bubble sort
      for(int i = 0; swapped; ) {
	swapped = false;
	i++;
	for(unsigned int j = 0; j < curr_orders.size()-i; j++) {
	  if(curr_orders[j].o_time().minute() > curr_orders[j+1].o_time().minute()) {
	    Order tmp = curr_orders[j];
	    curr_orders[j] = curr_orders[j+1];
	    curr_orders[j+1] = tmp;
	    swapped = true;
	  }
	}
      }
      //end bubble sort
      swapped = true;
      for(unsigned int l = 0; l < curr_orders.size(); l++) {
	sorted_orders[k+l] = curr_orders[l];
      }
      for(unsigned int i = 0; i < curr_orders.size(); i++) {
	k++;
      }
    }    

    
    /*****
	  End Date and Time sorting
    *****/
    
    for(unsigned int i = 0; i < sorted_orders.size(); i++) {
      double price = 0;
      int curr_order_id = sorted_orders[i].order();
      for(unsigned int j = 0; j < order_items.size(); j++) {
	int curr_menu_item = -1;
	if(order_items[j].order() == curr_order_id) {
	  curr_menu_item = order_items[j].menu_item();
	  for(unsigned int k = 0; k < menu_items.size(); k++) {
	    price += menu_items[k].item_price() * order_items[j].qty();
	  }
	}
      }
      prices.push_back(price);
    }

    cout << "\nID\tDate\t\tTime\tPrice\n\n";
    for(unsigned int i = 0; i < prices.size(); i++) {
      cout << sorted_orders[i].order() << '\t' << sorted_orders[i].o_date() << '\t' << sorted_orders[i].o_time() << "\t$" << prices[i] << '\n';
    }
  }
  /***
      end by RCD
      C.1a
  ***/

  

  /*********************************************************************/
  /*Created or Modified by WEP*/
  /*Show query, C.b*/
  /*********************************************************************/
  else if(entry == 'E' || entry == 'e')
    {
      cin.ignore(INT_MAX, '\n');	//clear any leftover data in cin buffer
      int order;	//table which user is requesting sales for
      bool found = false;	//true is table exists in orders
      int totalOrder = 0; //to count the number sales of a menu item
		
      cout << "Order ID" <<endl; //listing the item ID and item name
      for (unsigned int i = 0; i < orders.size() ; i++)
	{
	  cout << orders[i].order() <<endl;
	}
      cout << "Enter the order id which you would like to list the menu items." << endl;
      cout << "> ";
      cin >> order;
      while(!cin) 
	{	//if input is invalid
	  cin.clear();	//reset cin state
	  cin.ignore(INT_MAX, '\n');	//clear cin buffer
	  cout << "Invalid entry, please try again.\n";
	  cout << "> ";
	  cin >> order;
	}

      //searching the order id, make sure order id exist
      for(unsigned int i = 0; i < orders.size(); i++) 
	{	
	  if(order == orders[i].order()) 
	    {
	      found = true;	
	    }
	}

      if (found == true) // if order id exist
	{
	  vector<Order_Item> vec_OrderItem;
	  vector<Order::MenuAndOrder>	vec_MenuSeat; // vector using new struct
			
	  int item_id, ord_id, quantity;
	  float price;
	  string item_name;

	  //order items that have same order id with input
	  for(unsigned int i = 0; i < order_items.size(); i++) 
	    {	
	      if(order == order_items[i].order()) 
		{
		  vec_OrderItem.push_back(order_items[i]);
		}
	    }
	  //cout << vec_OrderItem.size() << endl;//testing

	  //menu items that have same menu item id 
	  for(unsigned int i = 0; i < vec_OrderItem.size(); i++) 
	    {	
	      Menu_Item menuItems = menuByID(vec_OrderItem[i].menu_item());

	      item_id = menuItems.item_id();
	      ord_id = vec_OrderItem[i].order();
	      quantity = vec_OrderItem[i].qty();
	      price = menuItems.item_price();
	      item_name = menuItems.item_name();

	      vec_MenuSeat.push_back(Order::MenuAndOrder(item_id, order, price, quantity, item_name));
	    }

	  //sorting price
	  sort(vec_MenuSeat.begin(), vec_MenuSeat.end());

	  for(unsigned int i = 0; i < vec_MenuSeat.size(); i++)
	    {
	      cout << "Name\t:" << vec_MenuSeat[i].menu_itemName << endl;
	      cout << "Price\t:" << vec_MenuSeat[i].menu_itemPrice << endl;
	      cout << "#\t:" << vec_MenuSeat[i].order_quantity << endl;
	      cout << "Total\t:" << vec_MenuSeat[i].menu_itemPrice * vec_MenuSeat[i].order_quantity << endl <<endl;
	    }
	}

    }
  /*********************************************************************/
  /*End part by WEP*/
  /*********************************************************************/


  
  else	//entry was neither A, B, nor C; 
    cout << "Invalid entry. Ending query.\n";	//inform user, return to main menu
  cin.ignore(INT_MAX, '\n');	//flush cin buffer of any potential leftover data


}
void Menu::find() const 
{
  /* Modified by RCD
     B.2a
  */
  char entry;	//record letter choic
  cout << "Find queries \n";
  cout << "Enter A to display total sales for a table.\n";	//use letters to make choice
  cout << "Enter B to display total sales for a given server.\n";
  cout << "Enter C to display total sales for a given menu item.\n";
  cout << "Enter D to print top five selling menu items by revenue (regardless of category).\n"; //Modified by EC, for part C.2c
  cout << "Enter E to display the order with the largest tab price.\n";	//RCD C.2d
  cout << "> ";
  cin >> entry;
  while(!cin) {	//if entry was invalid
    cin.clear();	//reset cin state
    cin.ignore(INT_MAX, '\n');	//clear cin buffer
    cout << "Invalid entry, please try again.\n";
    cout << "> ";
    cin >> entry;
  }
  if(entry == 'A' || entry == 'a') {
    cin.ignore(INT_MAX, '\n');	//clear any leftover data in cin buffer
    int table;	//table which user is requesting sales for
    bool found = false;	//true is table exists in orders
    vector<int> indices;	//indices of orders that contain table
    vector<int> order_ids;	//order_id numbers associated with table
    cout << "Enter the table which you would like to display total sales for.\n";
    cout << "> ";
    cin >> table;
    while(!cin) {	//if input is invalid
      cin.clear();	//reset cin state
      cin.ignore(INT_MAX, '\n');	//clear cin buffer
      cout << "Invalid entry, please try again.\n";
      cout << "> ";
      cin >> table;
    }
    for(unsigned int i = 0; i < orders.size(); i++) {	//search through vector Menu::orders for any order that is for the requested table
      if(table == orders[i].table()) {
	found = true;	//indicate that a valid order has been found
	indices.push_back(i);	//record index of order that is associated with requested table
      }
    }
    if(found) {
      for(unsigned int i = 0; i < indices.size(); i++) {	//loop records order_ids of orders associated with requested table
	order_ids.push_back(orders[indices[i]].order());
      }
      cout << "Seat ID\tOrder ID\tMenu Item ID\tQuantity\n";	//print out column headers for info display
      for(unsigned int i = 0; i < order_ids.size(); i++) {	//go through order_ids of orders associated with requested table
	int current_order_id = order_ids[i];	//record order_id of current vector subscript
	for(unsigned int j = 0; j < order_items.size(); j++) {	//go through Menu::order_items and print out any order_item that matches order_id of requested table
	  if(current_order_id == order_items[j].order()) {
	    cout << order_items[j].seat() << '\t' << order_items[j].order() << "\t\t" << order_items[j].menu_item() << "\t\t" << order_items[j].qty() << '\n';
	  }
	}
      }
    }
    else	//no order with a matching table_id was found
      cout << "ERROR: Table doesn't exist. Ending query.\n";	//inform user, return to main menu
  }
  /* END Modification by RCD
     for B.2a
  */

  /************************************************************/
  /*Modified by EC*/
  /*B.2b: Display total sales for a given server*/
  /************************************************************/
  else if(entry == 'B' || entry == 'b') {
    //write code block for when entry is B or b here - part B2b
    cin.ignore(INT_MAX, '\n');  //clear any leftover data in cin buffer
    int server;  //server which user is requesting sales for
    bool found = false;  //true is server exists in orders
    vector<int> indices;  //indices of orders that contain server
    vector<int> order_ids;  //order_id numbers associated with server
    cout << "Enter the server which you would like to display total sales for.\n";
    cout << "> ";
    cin >> server;
    while(!cin) {  //if input is invalid
      cin.clear();  //reset cin state
      cin.ignore(INT_MAX, '\n');  //clear cin buffer
      cout << "Invalid entry, please try again.\n";
      cout << "> ";
      cin >> server;
    }
    for(unsigned int i = 0; i < orders.size(); i++) {  //search through vector Menu::orders for any order that is for the requested server
      if(server == orders[i].server()) {
	found = true;  //indicate that a valid order has been found
	indices.push_back(i);  //record index of order that is associated with requested server
      }
    }
    if(found) {
      for(unsigned int i = 0; i < indices.size(); i++) {  //loop records order_ids of orders associated with requested server
	order_ids.push_back(orders[indices[i]].order());
      }
      cout << "Seat ID\tOrder ID\tMenu Item ID\tQuantity\n";  //print out column headers for info display
      for(unsigned int i = 0; i < order_ids.size(); i++) {  //go through order_ids of orders associated with requested server
	int current_order_id = order_ids[i];  //record order_id of current vector subscript
	for(unsigned int j = 0; j < order_items.size(); j++) {  //go through Menu::order_items and print out any order_item that matches order_id of requested server
	  if(current_order_id == order_items[j].order()) {
	    cout << order_items[j].seat() << '\t' << order_items[j].order() << "\t\t" << order_items[j].menu_item() << "\t\t" << order_items[j].qty() << '\n';
	  }
	}
      }
    }
    else  //no order with a matching table_id was found
      cout << "ERROR: Server doesn't exist. Ending query.\n";  //inform user, return to main menu
  }

  /*********************************************************************/
  /*Created or Modified by WEP*/
  /*Find query: total sales item, B2C*/
  /*********************************************************************/
  else if(entry == 'C' || entry == 'c') 
    {
      cin.ignore(INT_MAX, '\n');	//clear any leftover data in cin buffer
      int menu;	//table which user is requesting sales for
      bool found = false;	//true is table exists in orders
      int totalOrder = 0; //to count the number sales of a menu item
      cout << "Item ID\tItem Name" <<endl; //listing the item ID and item name
      for (unsigned int i = 0; i < menu_items.size(); i++)
	{
	  cout << menu_items[i].item_id() << "\t" << menu_items[i].item_name() <<endl;
	}
      cout << "Enter the menu item id which you would like to display total sales for." << endl;
      cout << "> ";
      cin >> menu;
      while(!cin) 
	{	//if input is invalid
	  cin.clear();	//reset cin state
	  cin.ignore(INT_MAX, '\n');	//clear cin buffer
	  cout << "Invalid entry, please try again.\n";
	  cout << "> ";
	  cin >> menu;
	}
	
      //Go through the menu items
      for (unsigned int i = 0; i < menu_items.size(); i++)
	{
	  if (menu == menu_items[i].item_id())
	    {
	      found = true;
	    }
	}
      vector<Order_Item> vec_OrderedItems = orderedItems(menu);
      if (found == true)//if found in menu items
	{
	  for (unsigned int i = 0; i < vec_OrderedItems.size(); i++)//everytime it found the same menu, quantity + 1
	    {
	      totalOrder += vec_OrderedItems[i].qty();
	    }

	  if (totalOrder == 0)//given no sales, or 0 quantity, show information
	    {
	      cout << "No sales for this item." << endl;
	    }
	  else
	    {
	      Menu_Item inputMenuID = menuByID(menu);
	      cout << "Item Name\t: "<< inputMenuID.item_name() << endl;
	      cout << "Ordered\t\t: "<< totalOrder << endl;
	      cout << "Price\t\t: "<< "$" << inputMenuID.item_price() << endl;
	      cout << "Total Sales\t: "<< "$" << totalOrder * inputMenuID.item_price() << endl;
	    }
	}
      else
	{
	  cout << "ERROR: Menu item doesn't exist. Ending query.\n";	//inform user, return to main menu
	}
    }
  /*********************************************************************/
  /*End part by WEP*/
  /*********************************************************************/

  /***********************************/
  /*Modified by EC for part C.2c*/
  /***********************************/

  else if (entry == 'D' || entry == 'd')
    {
      cin.ignore(INT_MAX, '\n');	//clear any leftover data in cin buffer
    
      Item_by_rev::Show_Top_Five(order_items, menu_items);   
    }
  /*End part C.2c by EC*/


  
  /*
    Modified by RCD
    C.2d
  */
  else if(entry == 'E' || entry == 'e') {
    vector<double> total_prices;
    vector<double> order_ids;
    double highest_price = -1;
    double highest_order_id = -1;
    int order_id = -1;
    for(unsigned int i = 0; i < orders.size(); i++) {
      order_id = orders[i].order();
      double price = 0;
      for(unsigned int j = 0; j < order_items.size(); j++) {
	int menu_item_id = -1;
	if(order_id == order_items[j].order()) {
	  menu_item_id = order_items[j].menu_item();
	  for(unsigned int k = 0; k < menu_items.size(); k++) {
	    if(menu_item_id == menu_items[k].item_id()) {
	      price += menu_items[k].item_price() * order_items[j].qty();
	    }
	  }
	}
      }
      total_prices.push_back(price);
      order_ids.push_back(order_id);
    }
    for(unsigned int i = 0; i < total_prices.size(); i++) {
      if(total_prices[i] > highest_price) {
	highest_price = total_prices[i];
	highest_order_id = order_ids[i];
      }
    }
    cout << "The order with the highest tab is order #" << highest_order_id << " with a total tab of $" << highest_price << ".\n";
  }
  /*
    End modification by RCD
    C.2d
  */
  
  else	//entry was neither A, B, C, D, nor E; RCD - part B
    cout << "Invalid entry. Ending query.\n";	//inform user, return to main menu: RCD - part B
  cin.ignore(INT_MAX, '\n');	//flush cin buffer of any potential leftover data: RCD - part B
}

void Menu::update()  
{
  cout << "Update queries \n";

  char entry;	//record letter choice
  cout << "Enter A to add a new order item to an existing order\n";	//use letters to make choice
  cout << "Enter B to add a new menu item using an existing recipe to an existing category.\n";
  cout << "Enter C to add new categories Soups, Salads and Sides.\n";
  cout << "Enter D to Add a new order given a server, table, date and time.\n";
  cout << "Enter E to add new menu item to an existing category.\n";
  cout << "Enter G to Delete a menu item in a certain category.\n";
  cout << "Enter F to delete an order item from a current order.\n";
  cout << "> ";
  cin >> entry;
  while(!cin) {	//if entry was invalid
    cin.clear();	//reset cin state
    cin.ignore(INT_MAX, '\n');	//clear cin buffer
    cout << "Invalid entry, please try again.\n";
    cout << "> ";
    cin >> entry;
  }
  if(entry == 'A' || entry == 'a') 
    {
      /************************************************************/
      /*Created or Modified by EC*/
      /*B.3a: Add new order item to an existing order*/
      /************************************************************/
      //int action;
      int order_ID;
      char seat_ID;
      int item_ID;
      int quantity;
      bool found=false;
      Order_Item new_item;
      vector<int> indices;

      //cout << "If you want to add a new order to an existing order, enter (1). \nIf you want to add a new menu item, enter (2). \n";
      //cin >> action;

      //Added for information by WEP
      cout << "Existing Order: " << endl;
      for (unsigned int j = 0; j < orders.size(); j++)
	{
	  cout << orders[j].order() << endl;
	}
      //End of Addition by WEP

      cout << "Enter the ID number of the order you want to add to: \n";
      cin >> order_ID;

      for(unsigned int i = 0; i < orders.size(); i++) {  //search through vector Menu::orders to make sure the order ID given is an existing order
	if(order_ID == orders[i].order()) {
	  found = true;  //indicate that a valid order has been found
	  indices.push_back(i);  //record index of order 
	}
      }
	
      //Added by WEP for D1
      if(found)
	{	
	  for(unsigned int j = 0; j < indices.size(); j++)
	    {
	      bool founditem = false;
	      //End of Addition by WEP
	      cout << "Please enter the seat letter[A-H]: \n";
	      cin >> seat_ID; //stores the seat letter

	      //Added by WEP for D1
	      if (seat_ID == 'A' || seat_ID == 'B' || seat_ID == 'C' || seat_ID == 'D' || seat_ID == 'E' || seat_ID == 'F' || seat_ID == 'G' || seat_ID == 'H')
		{
		  //End of Addition by WEP
		  cout << "Please enter the ID number for the item ordered: \n";
		  cin >> item_ID; //stores the item ID number

		  //Added by WEP for D1
		  for (unsigned int k = 0; k < menu_items.size(); k++)
		    {
		      if (item_ID == menu_items[k].item_id())
			{
			  founditem = true;
			}
		    }

		  if (founditem == true)
		    {
		      //End of Addition by WEP
		      cout << "Please enter the quantity of the item desired: \n";
		      cin >> quantity; // stores the quantity ordered
	
		      new_item = Order_Item(seat_ID, orders[indices[j]].order(), item_ID, quantity);
		      Menu::order_items.push_back(new_item);
		      cout << "New order has been added!" << endl; //Added by WEP for D1
		      break;
		    }
		  //Added by WEP for D1
		  else
		    {
		      cout << "Menu item doesn't exist." << endl; 
		    }
		}
	      else
		{
		  cout << "Seat only available from A - H, capital letter." << endl;
		}
	    }
	}
      else
	{
	  cout << "Order does not exist, please enter a valid order ID number.\n";
	  //End of Addition by WEP		
	}
    }
  else if(entry == 'B' || entry == 'b') 
    {
      /*
	Modified by RCD
	B3b
      */
      int menu_item_id;
      bool menu_item_exists = false;
      int cat_id;
      bool cat_exists = false;
      int recipe_id;
      int recipe_index;
      bool recipe_exists = false;
      string menu_item_name;
      Description descrip;
      cout << "Enter the ID of the new menu item.\n";
      cout << "> ";
      cin >> menu_item_id;
      while(!cin) {
	cin.clear();
	cin.ignore(INT_MAX, '\n');
	cout << "Invalid entry, please try again.\n";
	cout << "> ";
	cin >> menu_item_id;
      }
      for(unsigned int i = 0; i < menu_items.size() && !menu_item_exists; i++) {
	if(menu_item_id == menu_items[i].item_id() || (menu_item_id < 1000 || menu_item_id > 9999)) // Added by WEP. D3
	  menu_item_exists = true;
      }
      if(!menu_item_exists) {
	cout << "Enter the ID of the existing recipe.\n";
	cout << "> ";
	cin >> recipe_id;
	while(!cin) {
	  cin.clear();
	  cin.ignore(INT_MAX, '\n');
	  cout << "Invalid entry, please try again.\n";
	  cout << "> ";
	  cin >> recipe_id;
	}
	for(unsigned int i = 0; i < recipes.size() && !recipe_exists; i++) {
	  if(recipe_id == recipes[i].recipe()) {
	    recipe_exists = true;
	    recipe_index = i;
	  }
	}
	if(recipe_exists) {
	  cout << "Enter the ID of the existing category to which the menu item will be added.\n";
	  cout << "> ";
	  cin >> cat_id;
	  while(!cin) {
	    cin.clear();
	    cin.ignore(INT_MAX, '\n');
	    cout << "Invalid entry, please try again.\n";
	    cout << "> ";
	    cin >> cat_id;
	  }
	  for(unsigned int i = 0; i < categories.size() && !cat_exists; i++) {
	    if(cat_id == categories[i].getCategoryID())
	      cat_exists = true;
	  }
	  if(cat_exists) {
	    string item_name;
	    double item_price;
	    Description new_descrip;
	    string desc;
	    cout << "Enter name for new menu item.\n";
	    cout << "> ";
	    cin  >> item_name;
	    while(!cin) {
	      cin.clear();
	      cin.ignore(INT_MAX, '\n');
	      cout << "Invalid entry, please try again.\n";
	      cout << "> ";
	      cin >> item_name;
	    }
	    cout << "Enter price for new menu item.\n";
	    cout << "> ";
	    cin >> item_price;
	    while(!cin) {
	      cin.clear();
	      cin.ignore(INT_MAX, '\n');
	      cout << "Invalid entry, please try again.\n";
	      cout << "> ";
	      cin >> item_price;
	    }
	    new_descrip.setMenuItemID(menu_item_id);
	    new_descrip.setCategoryID(cat_id);
	    new_descrip.setRecipeId(recipe_id);
	    new_descrip.setMenuItemName(item_name);
	    new_descrip.setMenuItemPrice(item_price);
	    cout << "Enter description for new menu item.\n";
	    cout << "> ";
	    cin >> desc;
	    while(!cin) {
	      cin.clear();
	      cin.ignore(INT_MAX, '\n');
	      cout << "Invalid entry, please try again.\n";
	      cout << "> ";
	      cin >> desc;
	    }
	    new_descrip.setDescription(desc);
	    Menu_Item new_menu_item(menu_item_id, cat_id, recipe_id, item_name, item_price, new_descrip);
	    menu_items.push_back(new_menu_item);
	  }
	  else {
	    cout << "Category doesn't exist. Ending query.\n";
	  }
	}
	else {
	  cout << "Recipe doesn't exist. Ending query.\n";
	}
      }
      else {
	cout << "Menu item ID already exists or it is not 4 digit. Ending query.\n";
      }
    }
  /*
    Ending modification by RCD
    B3b
  */

  /*********************************************************************/
  /*Created or Modified by WEP*/
  /*Update query: add 3 more categories, B3C*/
  /*Error checking: no repetation, all id are unique, autogenerated, D3*/
  /*********************************************************************/
  else if(entry == 'C' || entry == 'c') 
    {
      bool alreadyinput = false;
      for (unsigned int i = 0; i < categories.size(); i++)
	{
	  if (categories[i].getCategoryID() == 1440)
	    {
	      alreadyinput = true;
	    }
	}
      if (alreadyinput == false)
	{
	  Category cat;
	  //insert 3 new categories, Soups, Salads, and Sides, user define the ID but the name is fixed

	  //cout << "Insert category id for Soups: ";
	  //int soupsID;
	  //cin >> soupsID;
	  cat.setCategoryID(1440);
	  cat.setCategoryName("Soups");
	  Menu::categories.push_back(cat);

	  //cout << "Insert category id for Salads: ";
	  //int saladsID;
	  //cin >> saladsID;
	  cat.setCategoryID(1220);
	  cat.setCategoryName("Salads");
	  Menu::categories.push_back(cat);

	  //cout << "Insert category id for Sides: ";
	  //int sidesID;
	  //cin >> sidesID;
	  cat.setCategoryID(1660);
	  cat.setCategoryName("Sides");
	  Menu::categories.push_back(cat);

	  cout << "3 new categories added!" << endl;
	  cout << "Current Categories:" << endl;
	  for (unsigned int i = 0; i < categories.size(); i++)
	    {cout << categories[i].getCategoryID() << " " << categories[i].getCategoryName() << endl;}
	}
      else
	{
	  cout << "You have already input this!" << endl;
	}
    }
  /*********************************************************************/
  /*End part by WEP*/
  /*********************************************************************/

  /*********************************************************************/
  /*Created or Modified by WEP*/
  /*Update query: add new order, C.e*/
  /*Error Checking: all category, order, recipe and menu item IDs are unique, D3 */
  /*********************************************************************/

  else if(entry == 'D' || entry == 'd')
    {
      int orderId, tableId, serverId, year, month, day, hour, minute;
      Date order_date;
      Time order_time;
      bool orderexist = false, fourdigit = true;

      cout << "Order ID: ";  //input order id
      cin >> orderId;

      for(unsigned int i = 0; i < orders.size(); i++)
	{
	  if (orderId == orders[i].order())
	    {
	      orderexist = true;
	    }
	}
      if (orderId < 1000 || orderId > 9999)
	{
	  fourdigit = false;
	}
      if (orderexist == false)
	{
	  if (fourdigit == true)
	    {
	      cout << "Table ID: "; //input table id
	      cin >> tableId;
	      cout << "Server ID: "; //input server id
	      cin >> serverId;
	      cout << "Day (1 - 31): ";
	      cin >> day;
	      cout << "Month (1 - 12): ";
	      cin >> month;
	      cout << "Year: ";
	      cin >> year;
	      order_date = Date(year, (Date::Month)month, day); //process date type
	      cout << "Hour: ";
	      cin >> hour;
	      cout << "Minute: ";
	      cin >> minute;
	      order_time = Time(hour, minute); //process time type

	      Order newOrder = Order(orderId, serverId, tableId, order_date, order_time);
	      orders.push_back(newOrder); //storing new order
	      cout << "New order added!" << endl;
	    }
	  else
	    {
	      cout << "Order ID must be 4 digits!" << endl;
	    }
	}
      else
	{
	  cout << "Order ID already exist!" << endl;
	}
    }
  /*********************************************************************/
  /*End part by WEP*/
  /*********************************************************************/


  /***********/
  /*Modified by EC for part C.3f*/
  /***********/
  else if(entry == 'E' || entry == 'e')
    {
      bool found = false;
      int selected_cat, index, new_id, new_recipe_id;
      string new_name, word; 
      string new_descr;
      Description new_descrip;
      double new_price;
      bool menuitemexist = false, recipeexist = false;// Added by WEP, D3
	
	
      cout << "Enter the ID number of the category you want to add to: \n";
      cin >> selected_cat;
			
      for(unsigned int i = 0; i < categories.size(); i++)
	{
	  if(categories[i].getCategoryID() == selected_cat)
	    { //makes sure that the category ID entered is an existing category
	      found = true;
	      index = i;
	    }
	}
		
      if(found)
	{		//Ask user for the new item's information
	  cout << "Please enter the new item ID: \n";
	  cin >> new_id;

	  // Added by WEP, D3
	  for (unsigned int i = 0; i < menu_items.size(); i++)
	    {
	      if (new_id == menu_items[i].item_id())
		{
		  menuitemexist = true;
		}
	    }
	  if (menuitemexist == false)
	    {
	      // End of Addition by WEP, D3
	      cout << "Please enter the new item recipe ID: \n";
	      cin >> new_recipe_id;

	      // Added by WEP, D3
	      for (unsigned int i = 0; i < recipes.size(); i++)
		{
		  if (new_recipe_id == recipes[i].recipe())
		    {
		      recipeexist = true;
		    }
		}
	      if (recipeexist == false)
		{
		  // End of Addition by WEP, D3
		  cout << "Please enter the new item name: \n";
		  cin >> new_name;
		  cout << "Please enter the new item price: \n";
		  cin >> new_price;
		  cout << "Please enter the new item description, followed by a # sign: \n";
		  cin >> new_descr;
		  //set the information given into a Description object
		  new_descrip.setMenuItemID(new_id);
		  new_descrip.setCategoryID(categories[index].getCategoryID());
		  new_descrip.setRecipeId(new_recipe_id);
		  new_descrip.setMenuItemName(new_name);
		  new_descrip.setMenuItemPrice(new_price);
		  new_descrip.setDescription(new_descr);
		  //use the input and the Description object to create a Menu_Item object
		  Menu_Item new_item = Menu_Item(new_id, categories[index].getCategoryID(), new_recipe_id, new_name, new_price, new_descrip);
		  Menu::menu_items.push_back(new_item); //store the new object in the menu_items vector
		  cout << "New item successfully added." << endl;
		}
	      // Added by WEP, D3
	      else
		{
		  cout << "Recipe ID already exist!" << endl;
		}
	    }
	  else
	    {
	      cout << "Menu item ID already exist!" << endl;
	    }
	  // End of Addition by WEP, D3
	}
      else //if category id entered is not found
	{
	  cout << "The category ID entered is not an existing category.\n";
	}	
    }
  /*End part C.3f by EC*/


  
  /*********************************************************************/
  /*Created or Modified by WEP*/
  /*Team Problem: Delete Menu Item*/
  /*********************************************************************/

  else if(entry == 'G' || entry == 'g')
    {
      int category_id, menu_id;
      bool foundcat = false, foundmenu = false;

      cout << "Enter the category ID contains menu that you want to be deleted : ";
      cin >> category_id;
      for(unsigned int i = 0; i < categories.size(); i++) 
	{	
	  if(category_id == categories[i].getCategoryID()) 
	    {
	      foundcat = true;	
	    }
	}

      cout << "Enter the Menu Item ID : ";
      cin >> menu_id;
      for(unsigned int i = 0; i < menu_items.size(); i++) 
	{	
	  if(menu_id == menu_items[i].item_id()) 
	    {
	      foundmenu = true;	
	    }
	}

      if (foundcat ==  true && foundmenu == true)//category found and menu id found
	{
	  //deleting process
	  if (Menu_Item::DeleteMenuItem(menu_items,category_id,menu_id))
	    {
	      cout << "Delete success" << endl;
	    } 
	  else
	    {
	      cout << "Delete failed" << endl;
	    } 
	}
      else
	{
	  cout << "Either category ID or menu item ID is invalid." << endl;//category or menu id invalid
	}
    }
  /*********************************************************************/
  /*End part by WEP*/
  /*********************************************************************/

  /*****
	Modified by RCD
	C - delete query #1
  *****/
  else if(entry == 'F' || entry == 'f') {
    int order_id;
    unsigned int item_num;
    bool order_found = false;
    bool deleted = false;
    Order_Item item_to_delete;
    vector<Order_Item> curr_order_items;
    cout << "Enter the order ID of the order which you would like to delete an Order Item from.\n";
    cout << "> ";
    cin >> order_id;
    while(!cin) {
      cin.clear();
      cin.ignore(INT_MAX, '\n');
      cout << "Invalid entry, please try again.\n";
      cout << "> ";
      cin >> order_id;
    }
    for(unsigned int i = 0; i < orders.size() && !order_found; i++) {
      if(order_id == orders[i].order())
	order_found = true;
    }
    if(order_found) {
      for(unsigned int i = 0; i < order_items.size(); i++) {
	if(order_id == order_items[i].order())
	  curr_order_items.push_back(order_items[i]);
      }
      cout << "The following order_items are part of order #" << order_id << ".\n";
      cout << "#\tOrder ID\tSeat ID\tMenu Item\tQty\n\n";
      for(unsigned int i = 0; i < curr_order_items.size(); i++) {
	cout << i+1 << '\t' << curr_order_items[i].order() << "\t\t" << curr_order_items[i].seat() << '\t' << curr_order_items[i].menu_item() << '\t' << curr_order_items[i].qty() << "\n";
      }
      cout << "Enter the # of the order_item you would like to delete.\n";
      cout << "> ";
      cin >> item_num;
      while(!cin) {
	cin.clear();
	cin.ignore(INT_MAX, '\n');
	cout << "Invalid entry, please try again.\n";
	cout << "> ";
	cin >> item_num;
      }
      if(item_num <= curr_order_items.size()) {
	item_to_delete = curr_order_items[item_num - 1];
	for(unsigned int i = 0; i < order_items.size() && !deleted; i++) {
	  if(item_to_delete == order_items[i]) {
	    order_items.erase(order_items.begin() + i);
	    deleted = true;
	    cout << "Order Item deleted successfully.\n";	  
	  }
	}
	if(!deleted) {
	  cout << "Unknown error, no order item was deleted.";
	}
      }
      else {
	cout << "# does not exist. Ending query.";
      }
    }
    else {
      cout << "Order ID not found. Ending query.\n";
    }
  }
  /*****
	End Modification by RCD
	C - delete query 1
  *****/

}  
/********/
/*Created by EC for Part D.1*/
/*********/

void Menu::write_catmenu() const {
  ofstream new_catmenu("../sample data/catmenu.dat");
		
  if(new_catmenu.is_open())
    {
      new_catmenu << categories.size() << endl;
      for(unsigned int i = 0; i < categories.size(); i++)
	{
	  new_catmenu << categories[i].getCategoryID() << "\t" << categories[i].getCategoryName() << endl;
	}
      new_catmenu << menu_items.size() << endl;
      for(unsigned int i = 0; i < menu_items.size(); i++)
	{
		new_catmenu << menu_items[i].item_id() << "\t" << menu_items[i].category() << "\t" << menu_items[i].recipe() << "\t" << menu_items[i].item_name() << "\t" << menu_items[i].item_price() << "\t" << menu_items[i].descrip().getDescription() << "\t#\t" << endl;
	}
      new_catmenu.close();
      cout << "Succesfully wrote new_catmenu.dat. \n";
    }
  else
    {
      cout << "File doesn't exist. Suggestion: new_catmenu.dat" << endl << endl;
    }
};
	
/*End Part D.1 by EC*/




/*****
      Written by RCD
      D.1 - write orders.dat
*****/
void Menu::write_orders() const{
  ofstream orders_write("../sample data/orders.dat");
  if(orders_write.is_open()) {
    orders_write << orders.size() << '\n';
    for(unsigned int i = 0; i < orders.size(); i++) {
      orders_write << orders[i].order() << '\t' << orders[i].server() << '\t' << orders[i].table() << '\t' << orders[i].o_date().year() << '\t' << orders[i].o_date().month() << '\t' << orders[i].o_date().day() << '\t' << orders[i].o_time().hour() << '\t' << orders[i].o_time().minute() << '\n';
    }
    orders_write << '\n' << order_items.size() << '\n';
    for(unsigned int i = 0; i < order_items.size(); i++) {
      orders_write << order_items[i].seat() << '\t' << order_items[i].order() << '\t' << order_items[i].menu_item() << '\t' << order_items[i].qty() << '\n';
    }
    orders_write.close();
    cout << "Writing orders.dat was successful.\n";
  }
  else
    cout << "Error occured while writing orders.dat.\n";
}
/*****
      End modification by RCD
      D.1 - write orders.dat
*****/

/*****
      Written by RCD
      D.1 - write recipes.dat
*****/
void Menu::write_recipes() const{
  ofstream recipes_write("../sample data/recipes.dat");
  if(recipes_write.is_open()) {
    recipes_write << ingredients.size() << '\n';
    for(unsigned int i = 0; i < ingredients.size(); i++) {
      recipes_write << ingredients[i].getIngredientId() << '\t' << ingredients[i].getRecipeId() << '\t' << ingredients[i].getAmount() << '\t' << ingredients[i].getUnits() << '\t' << ingredients[i].getName() << '\n';
    }
    recipes_write << '\n' << recipes.size() << '\n';
    for(unsigned int i = 0; i < recipes.size(); i++) {
      recipes_write << recipes[i].recipe() << '\t' << recipes[i].chef() << '\t' << recipes[i].instruct().getInstructions() << "\t#\n\n";
    }
    recipes_write.close();
    cout << "Writing recipes.dat was successful.\n";
  }
  else
    cout << "Error occured while writing recipes.dat.\n";
}
/*****
      End modification by RCD
      D.1 - write recipes.dat
*****/
